﻿using System.Reflection;
using Microsoft.AspNetCore.Mvc.Controllers;
using NiuX.AspNetCore.DynamicWebApi.Attributes;
using NiuX.AspNetCore.DynamicWebApi.Helpers;

namespace NiuX.AspNetCore.DynamicWebApi
{
    public class DynamicWebApiControllerFeatureProvider : ControllerFeatureProvider
    {
        protected override bool IsController(TypeInfo typeInfo)
        {
            var type = typeInfo.AsType();

            if (!typeof(IDynamicWebApi).IsAssignableFrom(type) || typeInfo.IsNotPublic || type.IsAbstract || typeInfo.IsGenericType)
            {
                return false;
            }

            //var attribute = ReflectionHelper.GetSingleAttributeOrDefault<DynamicWebApiAttribute>(typeInfo);

            //if (attribute == null || attribute.Disabled)
            //{
            //    return false;
            //}

            return true;
        }
    }
}